<template>
  <ConfigProvider :locale="getAntdLocale" :transform-cell-text="({ text }) => text || '--'">
    <AppProvider>
      <RouterView />
    </AppProvider>
  </ConfigProvider>
</template>

<script lang="ts" setup>
import { onMounted, onUnmounted, reactive } from 'vue'
import { ConfigProvider } from 'ant-design-vue'
import { AppProvider } from '/@/components/Application'
import { useTitle } from '/@/hooks/web/useTitle'
import { useLocale } from '/@/locales/useLocale'
import { useUserStoreWithOut } from '/@/store/modules/user'
const userStore = useUserStoreWithOut()

const { getAntdLocale } = useLocale()

useTitle()

function windowBeforeUnload(e) {
  console.log('触发beforeunload --->>>')
  console.log('xxxxxxxxxxxxxxxxxxxxxxx', e)
  e = e || window.event
  e.returnValue = '我在这写点东西...'

  Data._beforeUnload_time = new Date().getTime()
  // return '关闭提示';
}

const Data = reactive({
  _gap_time: 0,
  _beforeUnload_time: 0,
})

function unloadHandler(e) {
  Data._gap_time = new Date().getTime() - Data._beforeUnload_time
  //判断是窗口关闭还是刷新
  if (Data._gap_time <= 5) {
    userStore.logout()
  }
}

document.addEventListener(
  'contextmenu',
  function (e) {
    e.preventDefault()
  },
  false
)

// onMounted(() => {
//   window.addEventListener('beforeunload', windowBeforeUnload)
//   window.addEventListener('unload', unloadHandler)
// })

// onUnmounted(() => {
//   window.removeEventListener('beforeunload', windowBeforeUnload)
//   window.removeEventListener('unload', unloadHandler)
// })
</script>

<style>
.ant-progress-status-success .ant-progress-text {
  color: #000 !important;
}
</style>
